define(function(require){
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");
	//弹出框提示
	var outterAMD1 = require("../misc/js/wxaction");
	var utils = require("$UI/system/components/justep/common/utils");
	//引入极光推送
    var jpushInstance = require("../jpush");
	require("$UI/system/lib/cordova/cordova");
<<<<<<< HEAD
	require("cordova!jpush-phonegap-plugin");
=======
	require("cordova!cn.jpush.phonegap.JPushPlugin");
>>>>>>> db50113a5feef0605bbbc3a649d7e9809a12c455
	var RegistrationID="";
	//定义全局变量
	var websocket = null;
	var token="";
	
	var Model = function(){    
		this.callParent();
	};
	//图片路径转换
	Model.prototype.toUrl = function(url){
		return url ? require.toUrl(url) : "";
	};
	Model.prototype.windowReceiver1Receive = function(event){
<<<<<<< HEAD
	  if(event.data != undefined){
	   var accountData = this.comp("dengluzhuantai");
		accountData.clear();
		accountData.loadData([ event.data.rowData ]);
		accountData.first();
	  }else{
	    var dengz=this.comp("dengluzhuantai");
	 
	 if(window.token != null){
	   window.userstatus=1;
	 }else{
	   window.userstatus=0;
	 }
	  var zuotis = {
                        defaultValues : [
                        { "id":justep.UUID.createUUID(),
                          "username":window.name,
                          "userstatus":window.userstatus
                        }
                        ]
                        };
                        dengz.newData(zuotis);
	  }
		
=======
		var accountData = this.comp("dengluzhuantai");
		accountData.clear();
		accountData.loadData([ event.data.rowData ]);
		accountData.first();
>>>>>>> db50113a5feef0605bbbc3a649d7e9809a12c455
	};
    //点击登录按钮以后
	Model.prototype.loginBtnClick = function(event){
        var phoneInput = this.comp("nameInput").val();		
		var passwordInput = this.comp("passwordInput").val();
		var yin=function (){$('#wxloading').css("display","none")};
		var auditing = this.comp("dengluzhuantai");
		var receiver = this.comp("windowReceiver1");
		
		//获取token值
		$.ajax({
                type: "POST",
                url: window.yuming+'/sys/login/restful',     
		        async: false,
		        cache: false,
		        dataType: 'json',
		        data:{ username: phoneInput, password: passwordInput},
		        success: function(datas){
					          window.token = datas.token;
					        //  localStorage.token=datas.token;
					          token=datas.token;   
					          //获取用户信息      
					          $.ajax({
							           type: "GET",
							           url: window.yuming+'/users/current?login-token='+token,     
							           async: false,
							           cache: false,
							           success: function(data){
                                               //获取到的信息存在超级变量
								               window.name = data.username;
								            //   localStorage.name=data.username;
								               window.pass = passwordInput;
								               window.id = data.id;
								               window.createTime = data.createTime;
								               window.updateTime = data.updateTime;
								               window.nickname = data.nickname;
<<<<<<< HEAD
								               if(data.headImgUrl == null){
								                 data.headImgUrl='$UI/longrange/images/timg.jpg';
								               }
=======
>>>>>>> db50113a5feef0605bbbc3a649d7e9809a12c455
								               window.headImgUrl = data.headImgUrl;
								               window.phone = data.phone;
								               window.telephone = data.telephone;
								               window.email = data.email;
								               window.birthday = data.birthday;
								               window.sex = data.sex;
								               window.status = data.status;
								               window.type = data.type;
								               window.typestatus = data.typestatus;
								               window.userstatus=1;
								               var rows = auditing.getLastRow();		
								                 auditing.setValue("username",data.username,rows);
		                                         auditing.setValue("userstatus",1,rows);
								                //websocket关联
											    //判断当前浏览器是否支持WebSocket  
												if ('WebSocket' in window) {
<<<<<<< HEAD
													websocket = new WebSocket("ws://"+window.webyuming+"/ws/users/login?login-token="+window.token+"");
=======
													websocket = new WebSocket("wss://"+window.webyuming+"/ws/users/login?login-token="+window.token+"");
>>>>>>> db50113a5feef0605bbbc3a649d7e9809a12c455
												} else {
													websocket = new SockJS(window.yuming + "/sockjs/ws/users/login?login-token="+window.token+"");
												}
												//极光推送关联
									                  $.ajax({
									                  type: "GET",
									                  url: window.yuming+'/app/getRegsId?id='+window.id+'&regsId='+RegistrationID,     
									                  async: false,
									                  cache: false,
									                  success: function(data){
									                       receiver.windowEnsure(auditing.getLastRow());
								                          // justep.Shell.showPage("main");
								                      }
								                     
									            })
             
              
               
                                       }
                                       })
       
           
                 },
                 error: function(XMLHttpRequest){
                        var code=$.parseJSON(XMLHttpRequest.responseText);        
                        $('.wx_loading_inner').html(code.message);
		                $('#wxloading').css("display","block"); 
		                setTimeout(yin,2000);
         
                 }
                 });
	 };
     //用户注册完准备登录情况
	 Model.prototype.modelModelConstruct = function(event){
       if(window.name != ""){
         this.comp("nameInput").val(window.username);				 
       }
       if(window.pass != ""){
         this.comp("passwordInput").val(window.pass);
       }
       jpushInstance.getRegistrationID().done(function(id){
          RegistrationID=id;
        })
	};
 
<<<<<<< HEAD
	Model.prototype.registerBtnClick = function(event){
         justep.Shell.showPage("register");
	};
 
=======
>>>>>>> db50113a5feef0605bbbc3a649d7e9809a12c455
	return Model;
});